home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / kgdb-4.5 / ds3100.md / bfd / vm-core.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-30  |  10.6 KB  |  320 lines

  1. /* BFD back end for kernel core files on sprite
  2.    Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
  3.    Written by John Gilmore of Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* To use this file on a particular host, configure the host with these
  22.    parameters in the config/h-HOST file:
  23.  
  24.     HDEFINES=-DVM_CORE
  25.     HDEPFILES=vm-core.o
  26.  
  27.  */
  28.  
  29. #include "bfd.h"
  30. #include "sysdep.h"
  31. #include "libbfd.h"
  32. #include "libaout.h"           /* BFD a.out internal data structures */
  33.  
  34. #include <stdio.h>
  35. #include <sys/types.h>
  36. #include <sys/param.h>
  37. #include <sys/dir.h>
  38. #include <signal.h>
  39. #include <machine/reg.h>
  40. #include <kernel/dbg.h>
  41.  
  42. #include <sys/user.h>        /* After a.out.h  */
  43. #include <sys/file.h>
  44.  
  45. #include <errno.h>
  46. #define NOGAP
  47.  
  48. typedef struct {
  49.   StopInfo stopInfo;
  50.   Dbg_DumpBounds bounds;
  51. } CoreState;
  52.  
  53. struct vm_core_struct 
  54. {
  55.   asection *code_section;
  56.   asection *data_section;
  57.   asection *stack_section;
  58.   asection *cache_section;
  59.  
  60.   CoreState coreState;
  61. } *rawptr;
  62.  
  63.  
  64. #define core_state(bfd) (&((bfd)->tdata.vm_core_data->coreState))
  65. #define core_codesec(bfd) ((bfd)->tdata.vm_core_data->code_section)
  66. #define core_datasec(bfd) ((bfd)->tdata.vm_core_data->data_section)
  67. #define core_stacksec(bfd) ((bfd)->tdata.vm_core_data->stack_section)
  68. #define core_cachesec(bfd) ((bfd)->tdata.vm_core_data->cache_section)
  69.  
  70. StopInfo *
  71. bfd_get_vm_core_stopinfo(abfd)
  72.      bfd *abfd;
  73. {
  74.   return (&(abfd)->tdata.vm_core_data->coreState.stopInfo);
  75. }
  76.  
  77. Dbg_DumpBounds *
  78. bfd_get_vm_core_bounds(abfd)
  79.      bfd *abfd;
  80. {
  81.   return (&(abfd)->tdata.vm_core_data->coreState.bounds);
  82. }
  83.  
  84. Mach_RegState *
  85. bfd_get_vm_core_regs(abfd)
  86.      bfd *abfd;
  87. {
  88.   return (&(abfd)->tdata.vm_core_data->coreState.stopInfo.regs);
  89. }
  90.  
  91. Mach_RegState *
  92. bfd_get_vm_core_fpregs(abfd)
  93.      bfd *abfd;
  94. {
  95.   return (&(abfd)->tdata.vm_core_data->coreState.stopInfo.regs);
  96. }
  97.  
  98. /* Handle sprite kernel kgcore dump file.  */
  99.  
  100. /* ARGSUSED */
  101. bfd_target *
  102. vm_core_file_p (abfd)
  103.      bfd *abfd;
  104.  
  105. {
  106.   int val;
  107.   CoreState coreState;
  108.   /* This struct is just for allocating two things with one zalloc, so
  109.      they will be freed together, without violating alignment constraints. */
  110.  
  111.  
  112.   val = bfd_read ((void *)&coreState, 1, sizeof coreState, abfd);
  113. /*  val = read(fileno(abfd->iostream), (void *)&coreState, sizeof coreState);*/
  114.   if (val != sizeof coreState)
  115.     return 0;            /* Too small to be a core file */
  116.  
  117. #if 0
  118.   /* Sanity check perhaps??? */
  119.   if (u.u_dsize > 0x1000000)    /* Remember, it's in pages... */
  120.     return 0;
  121.   if (u.u_ssize > 0x1000000)
  122.     return 0;
  123.   /* Check that the size claimed is no greater than the file size. FIXME. */
  124. #endif
  125.  
  126.   /* OK, we believe you.  You're a core file (sure, sure).  */
  127.  
  128.   /* Allocate both the upage and the struct core_data at once, so
  129.      a single free() will free them both.  */
  130.   rawptr = (struct vm_core_struct *)bfd_zalloc (abfd, sizeof (struct vm_core_struct));
  131.   if (rawptr == NULL) {
  132.     bfd_error = no_memory;
  133.     return 0;
  134.   }
  135.   
  136.   abfd->tdata.vm_core_data = rawptr;
  137.  
  138.   rawptr->coreState = coreState; /*Copy the uarea into the tdata part of the bfd */
  139.  
  140.   /* Create the sections.  This is raunchy, but bfd_close wants to free
  141.      them separately.  */
  142.  
  143.   core_stacksec(abfd) = (asection *) zalloc (sizeof (asection));
  144.   if (core_stacksec (abfd) == NULL) {
  145.   loser:
  146.     bfd_error = no_memory;
  147.     free ((void *)rawptr);
  148.     return 0;
  149.   }
  150.   core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
  151.   if (core_datasec (abfd) == NULL) {
  152.   loser1:
  153.     free ((void *)core_stacksec (abfd));
  154.     goto loser;
  155.   }
  156.   core_cachesec (abfd) = (asection *) zalloc (sizeof (asection));
  157.   if (core_cachesec (abfd) == NULL) {
  158.   loser2:
  159.     free ((void *)core_datasec (abfd));
  160.     goto loser1;
  161.   }
  162.   core_codesec(abfd) = (asection *) zalloc (sizeof (asection));
  163.   if (core_stacksec (abfd) == NULL) {
  164.     free ((void *)rawptr);
  165.     goto loser2;
  166.   }
  167.  
  168.   core_stacksec (abfd)->name = ".stack";
  169.   core_datasec (abfd)->name = ".data";
  170.   core_cachesec (abfd)->name = ".cache";
  171.   core_codesec (abfd)->name = ".code";
  172.  
  173.   core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  174.   core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  175.   core_cachesec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
  176.   core_codesec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_CODE + SEC_HAS_CONTENTS;
  177.  
  178.   core_datasec (abfd)->_raw_size = coreState.bounds.kernelDataSize;
  179.   core_stacksec (abfd)->_raw_size = coreState.bounds.kernelStacksSize;
  180.   core_cachesec (abfd)->_raw_size = coreState.bounds.fileCacheSize;
  181.   core_codesec (abfd)->_raw_size = coreState.bounds.kernelCodeSize;
  182.  
  183.   /* What a hack... we'd like to steal it from the exec file,
  184.      since the upage does not seem to provide it.  FIXME.  */
  185.   core_datasec (abfd)->vma = coreState.bounds.kernelDataStart;
  186.   core_stacksec (abfd)->vma = coreState.bounds.kernelStacksStart;
  187.   core_cachesec (abfd)->vma = coreState.bounds.fileCacheStart;
  188.   core_codesec (abfd)->vma = coreState.bounds.kernelCodeStart;
  189.  
  190.   core_codesec (abfd)->filepos = sizeof coreState;
  191. #ifndef NOGAP
  192.   core_datasec (abfd)->filepos = coreState.bounds.kernelDataStart - coreState.bounds.kernelCodeStart + (sizeof coreState);
  193.   core_stacksec (abfd)->filepos = coreState.bounds.kernelStacksStart - coreState.bounds.kernelCodeStart + (sizeof coreState);
  194.   core_cachesec (abfd)->filepos = coreState.bounds.fileCacheStart - coreState.bounds.kernelCodeStart + (sizeof coreState);
  195. #else
  196.   core_datasec (abfd)->filepos = coreState.bounds.kernelCodeSize + (sizeof coreState);
  197.   core_stacksec (abfd)->filepos = coreState.bounds.kernelDataSize + coreState.bounds.kernelCodeSize + (sizeof coreState);
  198.   core_cachesec (abfd)->filepos = coreState.bounds.kernelStacksSize + coreState.bounds.kernelDataSize + coreState.bounds.kernelCodeSize + (sizeof coreState);
  199. #endif
  200.  
  201.   /* Align to word at least */
  202.   core_stacksec (abfd)->alignment_power = 2;
  203.   core_datasec (abfd)->alignment_power = 2;
  204.   core_cachesec (abfd)->alignment_power = 2;
  205.   core_codesec (abfd)->alignment_power = 2;
  206.  
  207.   abfd->sections = core_stacksec (abfd);
  208.   core_stacksec (abfd)->next = core_datasec (abfd);
  209.   core_datasec (abfd)->next = core_codesec (abfd);
  210.   core_codesec (abfd)->next = core_cachesec (abfd);
  211.   abfd->section_count = 4;
  212.  
  213.   return abfd->xvec;
  214. }
  215.  
  216. char *
  217. vm_core_file_failing_command (abfd)
  218.      bfd *abfd;
  219. {
  220.   return 0;
  221. }
  222.  
  223. /* ARGSUSED */
  224. int
  225. vm_core_file_failing_signal (abfd)
  226.      bfd *abfd;
  227. {
  228.   return abfd->tdata.vm_core_data->coreState.stopInfo.trapType;
  229. }
  230.  
  231. /* ARGSUSED */
  232. boolean
  233. vm_core_file_matches_executable_p  (core_bfd, exec_bfd)
  234.      bfd *core_bfd, *exec_bfd;
  235. {
  236.   return true;        /* FIXME, We have no way of telling at this point */
  237. }
  238.  
  239. /* No archive file support via this BFD */
  240. #define    vm_openr_next_archived_file    bfd_generic_openr_next_archived_file
  241. #define    vm_generic_stat_arch_elt        bfd_generic_stat_arch_elt
  242. #define    vm_slurp_armap            bfd_false
  243. #define    vm_slurp_extended_name_table    bfd_true
  244. #define    vm_write_armap            (PROTO (boolean, (*),    \
  245.      (bfd *arch, unsigned int elength, struct orl *map, \
  246.       unsigned int orl_count, int stridx))) bfd_false
  247. #define    vm_truncate_arname        bfd_dont_truncate_arname
  248. #define    aout_32_openr_next_archived_file    bfd_generic_openr_next_archived_file
  249.  
  250. #define    vm_close_and_cleanup        bfd_generic_close_and_cleanup
  251. #define    vm_set_section_contents        (PROTO(boolean, (*),    \
  252.          (bfd *abfd, asection *section, PTR data, file_ptr offset,    \
  253.          bfd_size_type count))) bfd_false
  254. #define    vm_get_section_contents        bfd_generic_get_section_contents
  255. #define    vm_new_section_hook        (PROTO (boolean, (*),    \
  256.     (bfd *, sec_ptr))) bfd_true
  257. #define    vm_get_symtab_upper_bound    bfd_0u
  258. #define    vm_get_symtab            (PROTO (unsigned int, (*), \
  259.         (bfd *, struct symbol_cache_entry **))) bfd_0u
  260. #define    vm_get_reloc_upper_bound        (PROTO (unsigned int, (*), \
  261.     (bfd *, sec_ptr))) bfd_0u
  262. #define    vm_canonicalize_reloc        (PROTO (unsigned int, (*), \
  263.     (bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
  264. #define    vm_make_empty_symbol        (PROTO (        \
  265.     struct symbol_cache_entry *, (*), (bfd *))) bfd_false
  266. #define    vm_print_symbol            (PROTO (void, (*),    \
  267.     (bfd *, PTR, struct symbol_cache_entry  *,            \
  268.      bfd_print_symbol_type))) bfd_false
  269. #define    vm_get_lineno            (PROTO (alent *, (*),    \
  270.     (bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
  271. #define    vm_set_arch_mach            (PROTO (boolean, (*),    \
  272.     (bfd *, enum bfd_architecture, unsigned long))) bfd_false
  273. #define    vm_find_nearest_line        (PROTO (boolean, (*),    \
  274.         (bfd *abfd, struct sec  *section,                \
  275.          struct symbol_cache_entry  **symbols,bfd_vma offset,        \
  276.          CONST char **file, CONST char **func, unsigned int *line))) bfd_false
  277. #define    vm_sizeof_headers        (PROTO (int, (*),    \
  278.     (bfd *, boolean))) bfd_0
  279.  
  280. #define vm_bfd_debug_info_start        bfd_void
  281. #define vm_bfd_debug_info_end        bfd_void
  282. #define vm_bfd_debug_info_accumulate    (PROTO (void, (*),    \
  283.     (bfd *, struct sec *))) bfd_void
  284. #define vm_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
  285. #define vm_bfd_relax_section bfd_generic_relax_section
  286. /* If somebody calls any byte-swapping routines, shoot them.  */
  287. void
  288. swap_abort()
  289. {
  290.   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
  291. }
  292. #define    NO_GET    ((PROTO(bfd_vma, (*), (         bfd_byte *))) swap_abort )
  293. #define    NO_PUT    ((PROTO(void,    (*), (bfd_vma, bfd_byte *))) swap_abort )
  294.  
  295. bfd_target vm_core_vec =
  296.   {
  297.     "vm-core",
  298.     bfd_target_unknown_flavour,
  299.     true,            /* target byte order */
  300.     true,            /* target headers byte order */
  301.     (HAS_RELOC | EXEC_P |    /* object flags */
  302.      HAS_LINENO | HAS_DEBUG |
  303.      HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  304.     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  305.     ' ',                           /* ar_pad_char */
  306.     16,                               /* ar_max_namelen */
  307.     3,                               /* minimum alignment power */
  308.     NO_GET, NO_PUT, NO_GET, NO_PUT, NO_GET, NO_PUT, /* data */
  309.     NO_GET, NO_PUT, NO_GET, NO_PUT, NO_GET, NO_PUT, /* hdrs */
  310.  
  311.     {_bfd_dummy_target, _bfd_dummy_target,
  312.      _bfd_dummy_target, vm_core_file_p},
  313.     {bfd_false, bfd_false,    /* bfd_create_object */
  314.      bfd_false, bfd_false},
  315.     {bfd_false, bfd_false,    /* bfd_write_contents */
  316.      bfd_false, bfd_false},
  317.     
  318.     JUMP_TABLE(vm)
  319. };
  320.